<?php

namespace App\Http\Controllers\Api;

use App\Http\Resources\ProjectCollection;
use App\model\Project;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ProjectController extends Controller
{
    public function index(Request $request){
        $project=Project::all();
        return new ProjectCollection($project);
    }
    /**
     * V2版项目列表 根据不同项目筛选
     * @authenticated
     */
    public function indexV2(Request $request){
        $user=User::find($request->user()->id);

        if (!empty($user->project_id)){
            $project=Project::where('is_display', '=', 1)->whereIn('project_id',$user->project_id)->get();
        }else{
            $project=collect([]);
        }
        if ( $user->checkPermissionTo('all')){
            $project=Project::where('is_display', '=', 1)->get();
        }
        return new ProjectCollection($project);
    }
}
